<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
-->
<template>
  <BasicModal v-bind="$attrs" :title="getTitle.value" @register="registerModal" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsMoOrderScOrderAdjustForm',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref, computed } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { ScOrder, scOrderAdjust } from '/@/api/mes/mo/order/scOrder';

  const emit = defineEmits(['success', 'register', 'modifyDate']);

  const { t } = useI18n('mo.order.scOrder');
  const { showMessage } = useMessage();
  const record = ref<ScOrder>({} as ScOrder);
  const getTitle = computed(() => ({
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: t('计划调整'),
  }));

  const inputFormSchemas: FormSchema[] = [
    {
      label: t('计划开始(车)'),
      field: 'scOrder.planStartDateWork',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD HH:mm',
        showTime: { format: 'HH:mm' },
        valueFormat: 'YYYY-MM-DD HH:mm',
      },
      required: true,
    },
  ];

  const [registerForm, { validate,resetFields }] = useForm({
    labelWidth: 120,
    schemas: inputFormSchemas,
    baseColProps: { lg: 24, md: 24 },
  });

  const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
    record.value = data;
    await resetFields();
  });

  async function handleSubmit() {
    try {
      const data = await validate();
      setTimeout(closeModal);
      emit('modifyDate', data);
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage('您填写的信息有误，请根据提示修正。');
      }
      console.log('error', error);
    } finally {
      // setModalProps({ confirmLoading: false });
    }
  }
</script>
